package com.wehealth.util;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap.CompressFormat;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.utils.StorageUtils;
import com.wehealth.R;

public class Common {
	// 信息打印tag
	public static final String TAG = "_HOK";
	
	
	//下载图片的配置 公共的(有图片下载的需调用)
	public static DisplayImageOptions options;
	/**
	 * 图片下载
	 * @param ctx 
	 */
	public static void initconfig(Context ctx)
	{
		//缓存的文件
		File cacheDir = StorageUtils.getOwnCacheDirectory(ctx, "UniversalImageLoader/Cache");
		//图片缓存配置
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(ctx).memoryCacheExtraOptions(480, 800) // max width, max height
		           .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75) // Can slow ImageLoader, use it carefully (Better don't use it)
		           .threadPoolSize(3)
		           .threadPriority(Thread.NORM_PRIORITY - 1)
		           .denyCacheImageMultipleSizesInMemory()
		           .offOutOfMemoryHandling()
		           .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation
		           .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
		           .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
		           //.imageDownloader(new BaseImageDownloader(context)) // default// connectTimeout (5 s), readTimeout (20 s)
		           .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
		           .enableLogging()
		           .build();
		ImageLoader.getInstance().init(config);
		
		//图片下载配置
		options = new DisplayImageOptions.Builder()
		.showStubImage(R.drawable.ic_stub)
		.showImageForEmptyUri(R.drawable.nophoto)
		.showImageOnFail(R.drawable.nophoto)
		.cacheInMemory()
		.cacheOnDisc()
		.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
		//下面这句是圆形的图像
		.displayer(new RoundedBitmapDisplayer(20))
		.build();
	}
}
